<template>
  <div>
    <my-header></my-header>
    <div class="userInfo">
      <el-form :model="userInfo" status-icon ref="ruleForm" label-width="100px">
        <el-form-item label="账号" prop="user">
          <el-input type="username" v-model="userInfo.username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="pass">
          <el-input type="password" v-model="userInfo.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model.number="userInfo.age"></el-input>
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model.number="userInfo.phone"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model.number="userInfo.email"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="modifyUser('ruleForm')">确认</el-button>
          <el-button type="primary" @click="goBack('ruleForm')">返回</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>

</template>

<script>
import { reqModifyUser } from "@/api/index";
import MyHeader from '@/components/MyHeader.vue';

export default {
  components: { MyHeader },
  name: "UserInfo",
  methods: {
    async modifyUser() {
      const result = await reqModifyUser(this.userInfo);
      if (result.code == 200) {
        alert("修改成功");
        this.$router.back();
      }
    },
    goBack() {
      this.$router.back();
    },
  },
  data() {
    return {
      userInfo: {
        id: this.$route.params.id,
        username: this.$route.params.username,
        password: this.$route.params.password,
        age: this.$route.params.age,
        phone: this.$route.params.phone,
        email: this.$route.params.email,
      },
    };
  },
};
</script>

<style>
.userInfo {
  margin-top: 100px;
  margin-bottom: 100px;
  margin-left: 500px;
  /* margin: 10%;  */
  height: 400px;
  width: 400px;
  text-align: center;
}
</style>